package com.danguo.happymonkey;

import java.util.ArrayList;

import android.opengl.GLES20;
import android.opengl.Matrix;

public class Lines
{
   private ArrayList<Line> theLines = new ArrayList<Line>();
   private float theAlpha = 0;
   private float theWhite = 0;
   private float theChange = 0.005f; 
   
   public Lines( float[][] anAdjacencyMatrix )
   {
      //TODO: implement use of the adjacencyMatrix for responding to
      //changes in visibility.
   }
   
   public void add( Line aLine )
   {
      theLines.add( aLine );
   }
   
   public void draw( float[] aViewMatrix, float[] aProjMatrix )
   {
      GLES20.glEnable(GLES20.GL_BLEND); 
      theAlpha = theAlpha + theChange;
      theWhite = theWhite + theChange;
      if( theAlpha > 1 )
      {
          theChange = -0.1f;
      }
      else if( theAlpha < 0.4f)
      {
         theChange = 0.005f;
      }
      float[] anMVPMatrix = new float[16];
      Matrix.multiplyMM( anMVPMatrix, 0, aProjMatrix, 0, aViewMatrix, 0 );
      for( int i = 0 ; i < theLines.size() ; i++ )
      {
         ( (Line)theLines.get( i ) ).setColor( theWhite, 1, theWhite, theAlpha );
         ( (Line)theLines.get( i ) ).draw( anMVPMatrix );
      }
      GLES20.glDisable( GLES20.GL_BLEND );
   }
}
